function [dat]=r_woa05(parameter)
%     This program is a modified and improved version of the "analysis.for"
%     FORTRAN sample program included with the World Ocean Atlas.
%
%     This program will read in any World Ocean Atlas 1-degree file.
%     These are all data files of the 360x180 1-degree WOA grids.
%
%
%-----------------------------------------------------------------------------

%-----------------------------------------------------------------------------
%
%
%
%     Parameter descriptions
%     
%     .   idim = longitude
%     .   jdim = latitude
%     .   kdim = standard depth levels
%     
%     33 Standard level depths (in meters):
%     
%     0,10,20,30,50,75,100,125,150,200,250,300,400,500,600,700,800,900,1000,
%     1100,1200,1300,1400,1500,1750,2000,2500,3000,3500,4000,4500,5000,5500
%     
%   NOTE:
%     
%     See the World Ocean Atlas 2005 documentation for variable depth
%     .  range and units.
%     
%     Land, missing, or "no value"  = -99.9999 for f8.4 read files 
%
%------------------------------------------------------------------------------
%clear all 
%close all

dirWOA05='/media/disk/OBSERVATIONS/CLIMATO/WOA05/';
if ~exist(dirWOA05,'dir')
    error('The data directory does not exist. Please double check the path in r_woa05.m')
end

idim=1440;
jdim=720;
idimx=idim/4;
jdimx=jdim/4;

kx=24;

% data(1:idimx,1:jdimx,1:kx)=NaN;
% lon(1:idim)=NaN;
% lat(1:jdim)=NaN;
depth=[0,10,20,30,50,75,100,125,150,200,250,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1750,2000,2500,3000,3500,4000,4500,5000,5500];
      
% kind=['NO3';...
%       'T  ';...
%       'S  '];
%   
% shortname=['n';'t';'s'];
% 
% if (strcmp(parameter,'T'))
%     iparam=2;
% elseif (strcmp(parameter,'S'))
%     iparam=3;
% elseif (strcmp(parameter,'NO3'))
%     iparam=1;
% end
%
% woa05(1:12,1:idimx,1:jdimx,1:kx)=NaN;

% ---- Create the Structure ...        
dat = struct('dummy',1);
 
% for imonth=1:12
%     
%     %    display(imonth)
%     
%     if imonth < 10    
%         filename=[dirWOA05,strtrim(kind(iparam,:)),'/',shortname(iparam),'0',num2str(imonth),'an1.2'];
%     else
%         filename=[dirWOA05,strtrim(kind(iparam,:)),'/',shortname(iparam),num2str(imonth),'an1.2'];
%     end
% 
%     % Attention pour les nitrates, T et S 33 niveaux en annuel (00) et saisonnier (13-16)
%     % et seulement 24 niveaux en mensuel
%     
%     a=load(filename);
%     
% % ----- Fortran method    
% %     iln=1;
% %     iel=1;
% %     for k=1:kx
% %         for j=1:jdimx
% %             for i=1:idimx
% %                 if iel > 10
% %                     iel=1;
% %                     iln=iln+1;
% %                 end
% %                 data(i,j,k)=a(iln,iel);
% %                 iel=iel+1;
% %             end
% %         end
% %     end
% 
% % ----- MATLAB method
%     data=reshape(a',[idimx jdimx kx]);    
%     
%     data(find(data<-89))=NaN;
%     lat=(1:180)-(90+0.5);
%     data=data([181:360 1:180],:,:);
%     lon=[181:360 1:180]-0.5;
%     lon(find(lon>180))=lon(find(lon>180))-360;
%     
%     woa05(imonth,:,:,:)=data;
% 
% end % imonth
% 
% dat.data=permute(woa05,[4 2 3 1]);
% dat.depthdata=depth(1:kx);
% dat.timedata=1:12;
% dat.londata=lon;
% dat.latdata=lat;  

a=load([dirWOA05,'/WOA05_',parameter,'.mat']); % Generated using creamat_fromASCIIclim.m

eval(['dat.data=permute(a.woa05_',parameter,',[4 2 3 1]);'])
dat.depthdata=depth(1:kx);
dat.timedata=1:12;
dat.londata=a.lon;
dat.latdata=a.lat;  

a=[];
clear a

% ---- Clean the Structure ...
dat=rmfield(dat,'dummy');    
